package train48days;

import java.util.Scanner;

public class 数根 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            String a = sc.next();
            while (a.length()>1){
                int sum = 0;
                for (int i = 0; i < a.length(); i++) {
                    sum+=a.charAt(i)-'0';
                }
                a=String.valueOf(sum);
            }
            System.out.println(a);
        }
    }
}
